package com.thingsgrid.device.controller;

import com.thingsgrid.device.entity.ConfigRecord;
import com.thingsgrid.device.service.IConfigRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springblade.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
//@AllArgsConstructor
@RequestMapping("/configRecord")
@Api(value = "配置记录信息接口", tags = "接口")
public class ConfigRecordController {
	@Autowired
	private IConfigRecordService configRecordService;
	/**
	 * 新增
	 */
	@PostMapping("/submit")
	@ApiOperation(value = "新增操作", notes = "传入configRecord实体", position = 1)
	public void save(@Valid @RequestBody ConfigRecord configRecord) {
		configRecordService.saveConfigRecord(configRecord);
	}

	/**
	 * 删除
	 */
	@PostMapping("/remove")
	@ApiOperation(value = "逻辑删除", notes = "传入ids", position = 2)
	public void remove(@ApiParam(value = "主键集合", required = true) @RequestParam Character ids) {
		configRecordService.removeConfigRecord(ids);
	}

	/**
	 * 修改
	 */
	@PostMapping("/update")
	@ApiOperation(value = "修改", notes = "传入shadow", position = 3)
	public void update(@Valid @RequestBody ConfigRecord configRecord) {
		configRecordService.updateConfigRecord(configRecord);
	}

	/**
	 * 查找所有
	 */
	@GetMapping("/selectAll")
	@ApiOperation(value = "查询所有", notes = "", position = 4)
	public R<List<ConfigRecord>> selectAll() {
		return R.data(configRecordService.findAll());
	}
	/**
	 * 根据id查信息
	 */
	@GetMapping("/detail")
	@ApiOperation(value = "查询一个", notes = "传递记录id", position = 5)
	public ConfigRecord selectById(@ApiParam(value = "configRecordId", required = true) @RequestParam Character configRecordId) {
		//productService.updateProduct(product);
		return configRecordService.findConfigRecordById(configRecordId);
	}
	/**
	 * 分页查询
	 */
//	@GetMapping("/list")
//	@ApiOperation(value = "分页", notes = "传入页数和每页显示的条数", position = 6)
//	public List<Product> pageList(@ApiParam(value = "页数和条数", required = true)
//								  @RequestParam Integer current, Integer size){
//		return productService.findAll(current,size);
//
//	}

	/**
	 * 用户列表
	 */
	@GetMapping("/list")
	@ApiOperation(value = "列表", notes = "传入account和realName", position = 2)
	public R<List<ConfigRecord>> pageList(@ApiParam(value = "页数和条数", required = true)
									@RequestParam Integer current, Integer size){
		return R.data(configRecordService.findAll(current,size));

	}
}
